package com.nf.service;

import com.nf.entity.Student2;
import com.nf.mapper.TestDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class TestServiceImp implements TestService {

    @Autowired
    private TestDao testDao;

    public void setTestDao(TestDao testDao) {
        this.testDao = testDao;
    }

    public TestServiceImp(TestDao testDao) {
        System.out.println("TestServiceImp被实例1");
        this.testDao = testDao;
    }

    private float rate;//它只是一个TestServiceImp里面的临时属性 不用@Autowried注解

    public void setRate(float rate) {
        this.rate = rate;
    }

    private float rate2;

    public void setRate2(float rate2) {
        this.rate2 = rate2;
    }

    public TestServiceImp() {
        System.out.println("TestServiceImp被实例2");
    }

    @Override
    public String getDate() {
        Date date = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        String dateStr =  sf.format(date);
        return dateStr;
    }

    @Override
    public String getString() throws SQLException {
        return testDao.getFloat() / rate + "美元";
    }

    @Override
    public String getCarDiscount(int discount) {
        return testDao.getCar(discount).getPrivce()* rate2 + "元";
    }

    @Override
    public List<Student2> getListStudent2() {
        List<Student2> student2List = testDao.getDaoListStudent2();
        return student2List;
    }

    @Override
    public boolean getDeteleStudent2(int id) {//
        boolean ok = testDao.getDaoDeteleStudent2(id);
        if(ok){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Student2 getJDBCStudent2() {
        return testDao.getDaoJDBCStudent2();
    }
}
